package cn.com.chengmandian.core.common.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.RandomUtil;

import java.util.Date;

public class BillNoUtil {
    /**
     * 雪花算法获取订单ID
     * @param pre 单号ID前缀，自定义即可
     * @return
     */
    public static String getSimpleNo(String pre) {
        return pre + IdUtil.getSnowflake().nextId();
    }

    public static String getDateNo(String pre, Integer length) {
        String no = "000000000" + RandomUtil.randomNumbers(length);
        no = no.substring(no.length() - length, no.length());
        return pre + DateUtil.format(new Date(), "yyMMddHH") + no;
    }
}
